package com.x.cookie;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName: CookieController
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.09.11 21:54
 */

@Controller
@RequestMapping("cookie")
@ResponseBody
public class CookieController {

    //接收cookie
    @RequestMapping("data")
    public String date(@CookieValue(value = "cookie1") String value){
        System.out.println(value);
        return value;
    }

    @GetMapping("saveCookie")
    public String saveCookie(HttpServletResponse response){
        Cookie cookie = new Cookie("cookie1","root");
        response.addCookie(cookie);
        return "cookie send";
    }
}
